<?php
/**
 * Created by PhpStorm.
 * Author: kaodou
 * Date: 2017/12/12
 * Time: 14:00
 */

namespace App\Http\Admin\Category\Controllers;


use Framework\BaseClass\Http\Admin\Controller;
use App\Http\Admin\Website\Models\Menu;
use App\Eloquent\Ygt\CategoryFields;
use App\Engine\Product as EngineProduct;

class FieldsController extends Controller
{
    protected $modelName = 'CategoryFields';
    protected $company = false;

    protected $rules = [
        'field_name' => 'bail|required',
        'sort_id' => 'required',
        'field_type' => 'required',
        'is_must' => 'required',
    ];

    public function __construct()
    {
        parent::__construct();
        $this->model = new CategoryFields();

    }

    protected function _orderby(){
        return ['sort_id','asc'];
    }
    protected function _vdata(){
        $fieldsType = EngineProduct::fieldsType();
        foreach ($fieldsType as $k=>$v){
            $fieldsType[$k] = $v['title'];
        }


        $categoryId = request('category_id');

        $data = ['fieldsType'=>json_encode($fieldsType),'categoryId'=>$categoryId];

        return $data;
    }

    protected function _where(){

        $where = [];
        if($categoryId = request('category_id')){
            $where['category_id'] = $categoryId;
        }
        return $where;
    }

    protected function _cdata(){
        $data = [];
        $data['category_id'] = request('category_id');
        return $data;
    }
//    protected function _hdata($lists)
//    {
//        $result         = collect($lists)->sortBy('type')->values()->all();
//        return $result;
//    }
}